package cn.chen.miaosha.result;

public class CodeMsg {

   private int code;
   private String msg;

    //通用的错误码
    public static CodeMsg SUCCESS = new CodeMsg(0, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常：%s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500101, "请求非法");
    //登录模块 5002XX
    public static CodeMsg SESSION_ERROR = new CodeMsg(500210, "Session不存在或者已经失效");
    public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "登录密码不能为空");
    public static CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "手机号不能为空");
    public static CodeMsg MOBILE_ERROR = new CodeMsg(500213, "手机号格式错误");
    public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误");

    //商品模块

    //订单模块
    public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500400, "订单不存在");

    //秒杀模块
    public static CodeMsg MIAOSHA_OVER = new CodeMsg(500500, "商品已经秒杀完了");
    public static CodeMsg REPEATE_MIAOSHA = new CodeMsg(500501, "不能重复秒杀");


    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CodeMsg() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static CodeMsg getSUCCESS() {
        return SUCCESS;
    }

    public static void setSUCCESS(CodeMsg SUCCESS) {
        CodeMsg.SUCCESS = SUCCESS;
    }

    public static CodeMsg getServerError() {
        return SERVER_ERROR;
    }

    public static void setServerError(CodeMsg serverError) {
        SERVER_ERROR = serverError;
    }

    public static CodeMsg getBindError() {
        return BIND_ERROR;
    }

    public static void setBindError(CodeMsg bindError) {
        BIND_ERROR = bindError;
    }

    public static CodeMsg getSessionError() {
        return SESSION_ERROR;
    }

    public static void setSessionError(CodeMsg sessionError) {
        SESSION_ERROR = sessionError;
    }

    public static CodeMsg getPasswordEmpty() {
        return PASSWORD_EMPTY;
    }

    public static void setPasswordEmpty(CodeMsg passwordEmpty) {
        PASSWORD_EMPTY = passwordEmpty;
    }

    public static CodeMsg getMobileEmpty() {
        return MOBILE_EMPTY;
    }

    public static void setMobileEmpty(CodeMsg mobileEmpty) {
        MOBILE_EMPTY = mobileEmpty;
    }

    public static CodeMsg getMobileError() {
        return MOBILE_ERROR;
    }

    public static void setMobileError(CodeMsg mobileError) {
        MOBILE_ERROR = mobileError;
    }

    public static CodeMsg getMobileNotExist() {
        return MOBILE_NOT_EXIST;
    }

    public static void setMobileNotExist(CodeMsg mobileNotExist) {
        MOBILE_NOT_EXIST = mobileNotExist;
    }

    public static CodeMsg getPasswordError() {
        return PASSWORD_ERROR;
    }

    public static void setPasswordError(CodeMsg passwordError) {
        PASSWORD_ERROR = passwordError;
    }

    public CodeMsg fillArgs(Object... args){
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code,message);
    }

    @Override
    public String toString() {
        return "CodeMsg{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }
}
